import 'package:fish_redux/fish_redux.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hayll_app_village_master/hayll/network/yll_network.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_grid_component/bean/village_grid_response.dart';
import 'package:hayll_app_village_master/hayll/village_manager/home/village_simple_component/action.dart';
import 'package:hayll_app_village_master/hayll/village_manager/network/village_action.dart';
import 'action.dart';
import 'state.dart';

Effect<VillageGridState> buildEffect() {
  return combineEffects(<Object, Effect<VillageGridState>>{
    VillageGridAction.action: _onAction,
    Lifecycle.initState: _requestVillageHouseGrid,
    // VillageSimpleAction.chooseHouseChanged: _requestVillageHouseGrid,
  });
}

void _onAction(Action action, Context<VillageGridState> ctx) {}

void _requestVillageHouseGrid(Action action, Context<VillageGridState> ctx) {
  var params = {'villageId': 118};
  YllNetwork.requestPost(VillageAction.getVillageGrid, params: params,
      success: (json) {
    ctx.state.villageGrid = VillageGridResult.fromJson(json);
    ctx.dispatch(VillageGridActionCreator.refreshUI());
  }, failed: (errorCode, errorMsg) {
    Fluttertoast.showToast(msg: '$errorCode,$errorMsg');
  });
}
